package com.jiezuo.auth.controller;

import com.jiezuo.auth.entity.PermissionApi;
import com.jiezuo.auth.service.PermissionApiService;
import com.jiezuo.common.base.BaseController;
import com.jiezuo.common.enums.ResultEnums;
import com.jiezuo.common.util.ResultUtil;
import com.jiezuo.common.vo.Result;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @description   数据权限表
* @author        庞留杰
* @date          2022/01/18 18:08
* @version       V1.0
**/
@Slf4j
@Transactional
@RequestMapping("/permissionApi")
@RestController
//数据权限表", tags = {"数据权限表接口"})
public class PermissionApiController  extends BaseController{

    @Autowired
    private PermissionApiService service;

    //通过权限资源ID查询", notes = "通过权限资源ID查询")
    @GetMapping("/findByPermissionId")
    public Result<List<PermissionApi>> findByPermissionId(String permission_id) {
        List<PermissionApi> list = service.findByPermissionId(permission_id);
        return new ResultUtil<List<PermissionApi>>().setData(list);
    }


    //删除", notes = "删除【逻辑删除】")
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable String id) {
        boolean boo = service.delete(id);
        if(boo){
            return new ResultUtil().setSuccessMsg(ResultEnums.OK.getReasonPhraseCN());
        }else {
            return new ResultUtil().setErrorMsg(ResultEnums.FAIL.getReasonPhraseCN());
        }
    }

    //添加数据权限", notes = "添加")
    @PostMapping("/edit")
    public Result edit(@RequestBody PermissionApi permissionApi) {
        boolean boo = service.edit(permissionApi);
        if(boo){
            return new ResultUtil().setSuccessMsg(ResultEnums.OK.getReasonPhraseCN());
        }else {
            return new ResultUtil().setErrorMsg(ResultEnums.FAIL.getReasonPhraseCN());
        }
    }


}
